<?php
/**
 * @package		Joomla.Site
 * @subpackage	plg_content_rating
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('JPATH_BASE') or die;

jimport('joomla.utilities.date');

class PlgContentMetadata extends JPlugin
{

	public function onContentBeforeSave($context, $article, $isNew){

		if($context != 'com_content.article') return true;
		if(trim($article->metadesc) != '') return true;

		//print_r($article);

		if($article->fulltext != '')
			$article->metadesc	= strip_tags($article->introtext);
		else{
			$article_content = strip_tags($article->introtext);
			$meta_len = $this->params->get('meta_length');

			$article->metadesc = substr($article_content,0,$meta_len).'...';
		}

		//print_r($article->metadesc);
		//exit();
		return true;
	}

	public function onContentBeforeDisplay($context, &$row, &$params, $page = 0)
	{
		$app = JFactory::getApplication();
		if ($app->isAdmin())
		{
			return;
		}

		if($this->params->get('allow_expired_article') == 0) return;

		$jinput = JFactory::getApplication()->input;

		$option = $jinput->get->get('option');
		$view = $jinput->get->get('view');
		$layout = $jinput->get->get('layout');
		$Itemid = $jinput->get->get('Itemid');
		$catid = $jinput->get->get('catid');
		$id = $jinput->get->get('id');
		//print_r($this->params->get('expired_article'));
		if(in_array($catid,$this->params->get('expired_article'))){

			if($view == 'article'){

				if($row->featured == 0){

					$row->expired = JText::_('TITLE_EXPIRED');
				}
			}
		}

		return true;

	}
}
